package com.iyundao.io.mapper;

import com.iyundao.io.model.SignIn;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;

@Repository
public interface SignInMapper {
    @Insert({
        "insert into signin (id, partymemberid, ",
        "activityid, signintime)",
        "values (#{id,jdbcType=INTEGER}, #{partymemberid,jdbcType=INTEGER}, ",
        "#{activityid,jdbcType=INTEGER}, #{signintime,jdbcType=TIMESTAMP})"
    })
    int insert(SignIn record);

    @InsertProvider(type=SignInSqlProvider.class, method="insertSelective")
    int insertSelective(SignIn record);

    @Select("select s.id,s.signintime,a.activitytitle from signin s" +
            "inner join activitymodel a" +
            "on s.activityid = a.id" +
            " where s.partymemberid=#{partymemberid,jdbcType=INTEGER}")
    List<SignIn> selectByPartymemberId(Integer partymemberid);

    @Select("select count(*) from signin " +
            "where partymemberid=#{partymemberid,jdbcType=INTEGER} " +
            "and activityid=#{activityid,jdbcType=INTEGER} " +
            "and (signintime BETWEEN #{signintime,jdbcType=TIMESTAMP} and" +
            "#{signintime1,jdbcType=TIMESTAMP})")
    int findnum(Integer partymemberid, Integer activityid, Date signintime, Date signintime1);

    @Select("select count(*) from signin " +
            "where partymemberid=#{partymemberid,jdbcType=INTEGER} " +
            "and activityid=#{activityid,jdbcType=INTEGER} ")
    int selectSum(SignIn signIn);
}